@echo off
CHCP 65001
if "%1" == "" (echo 请在命令后空一格输入服务器IP，例: .\cert.bat 192.169.1.111
goto :EOF
)

echo [req]>>cert.cnf
echo distinguished_name = req_distinguished_name>>cert.cnf
echo x509_extensions = v3_req>>cert.cnf
echo prompt = no>>cert.cnf
echo [req_distinguished_name]>>cert.cnf
echo C = CN>>cert.cnf
echo ST = SX>>cert.cnf
echo L = SMCity>>cert.cnf
echo O = HDD CO>>cert.cnf
echo OU = MyDivision>>cert.cnf
echo CN = %1>>cert.cnf
echo [v3_req]>>cert.cnf
echo keyUsage = critical, digitalSignature, keyAgreement>>cert.cnf
echo extendedKeyUsage = serverAuth>>cert.cnf
echo subjectAltName = @alt_names>>cert.cnf
echo [alt_names]>>cert.cnf
echo IP.1 = %1>>cert.cnf

..\tool\openssl\bin\openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout %1cert.key -out %1cert.pem -config cert.cnf -sha256

echo 证书已生成，文件是%1cert.pem %1cert.key
del cert.cnf